def isHappy(n):
    def count(m):
        global flag
        lst.append(int(m))
        result = 0
        for i in range(len(m)):
            result += int(m[i])**2
            if result == 1:
                flag = 1
            elif result in lst:
                flag = 0
            else:
                count(str(result))
    lst = []
    m = str(n)
    count(m)
    return flag == 1